<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加会员</title>
    <script src="https://www.layuicdn.com/auto/layui.js" v="2.5.6" e="layui"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/mobile/need/layer.css" rel="stylesheet">
    <link rel="stylesheet" href="static/css/style.css">
    <script src="https://cdn.bootcss.com/vue/2.5.10/vue.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.js"></script>
</head>
<body>
<div id="cvv">
    <!--顶栏-->
    <header>
        <div style="float: right">
            <i  class="layui-icon  layui-anim layui-anim-rotate layui-anim-loop" style="font-size: 30px; color: #969baa;">&#xe614;</i>&nbsp; &nbsp; &nbsp;
        </div>
    </header>

    <div class="main" id="app">
        <!--左栏-->
        <div class="left">
            <ul class="cl" >
                <!--顶级分类-->
                <li v-for="vo,index in menu" :class="{hidden:vo.hidden}">
                    <a href="javascript:;"  :class="{active:vo.active}"  @click="onActive(index)">
                        <i class="layui-icon" v-html="vo.icon"></i>
                        <span v-text="vo.name"></span>
                        <i class="layui-icon arrow" v-show="vo.url.length==0">&#xe61a;</i> <i v-show="vo.active" class="layui-icon active">&#xe623;</i>
                    </a>
                    <!--子级分类-->
                    <div v-for="vo2,index2 in vo.list">
                        <a href="javascript:;" :class="{active:vo2.active}" @click="onActive(index,index2)" v-text="vo2.name"></a>
                        <i v-show="vo2.active" class="layui-icon active">&#xe623;</i>
                    </div>
                </li>
            </ul>
        </div>
        <!--右侧-->
        <div class="dv">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>添加会员</legend>
            </fieldset>
            <form action="" class="layui-form" method="post" lay-filter="dataFrm" id="dataFrm">
                <div class="layui-form-item">
                    <div class="layui-dv">
                        <label class="layui-form-label">会员名称</label>
                    <div class="layui-input-dv">
                        <select name="name"  id="sel" lay-filter="test">

                        </select>
                    </div>
                    <div class="layui-dv">
                        <label class="layui-form-label">邮箱:</label>
                        <div class="layui-input-dv">
                            <input type="text" name="email"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-dv">
                        <label class="layui-form-label">联系方式:</label>
                        <div class="layui-input-dv">
                            <input type="text" name="u_phone"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-dv">
                        <label class="layui-form-label">开始时间:</label>
                        <div class="layui-input-dv">
                            <input type="text" name="starttime" id="starttime"  readonly="readonly" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-dv">
                        <label class="layui-form-label">结束时间:</label>
                        <div class="layui-input-dv">
                            <input type="text" name="endTime" id="endTime" readonly="readonly"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-dv">
                        <label class="layui-form-label">会员等级:</label>
                        <div class="layui-input-dv">
                            <select name="vip_level" lay-verify="">
                                <option value="">请选择一个会员等级</option>
                                <option value="初级会员">初级会员</option>
                                <option value="中级会员">中级会员</option>
                                <option value="高级会员">高级会员</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-dv">
                        <label class="layui-form-label">性别:</label>
                        <div class="layui-input-dv">
                            <input type="radio" name="sex" value="男" title="男" checked>
                            <input type="radio" name="sex" value="女" title="女" checked>
                        </div>
                    </div>
                    <div class="layui-dv">
                        <label class="layui-form-label">年龄:</label>
                        <div class="layui-input-dv">
                            <input type="text" name="age" id="age"   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-dv">
                        <label class="layui-form-label">积分:</label>
                        <div class="layui-input-dv">
                            <input type="text" name="integral" id="integral"   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="text-align: center;">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-icon layui-icon-release" lay-filter="sub" lay-submit="">提交</button>
                        <button type="reset" class="layui-btn layui-btn-warm layui-btn-sm layui-icon layui-icon-refresh" >重置</button>
                    </div>
                </div>
        </form>
        </div>
    </div>
</div>


<script src="static/layui/layui.js"></script>
<script>

    layui.use([ 'form','laydate','layedit' ],function(){
        var form = layui.form;
        var layedit = layui.layedit
        var laydate=layui.laydate;
        //刷新界面 所有元素
        form.render();
        laydate.render({
            elem:'#starttime'
        });
        laydate.render({
            elem:'#endTime'
        })





        $(function () {
            $.ajax({
                type: "post",
                url: "/user/selectusername",
                success: function (data) {
                    var dv = JSON.parse(data);
                    for(var i=0;i<dv.length;i++){
                        console.log(dv[i]);
                        $("#sel").append("<option value='"+dv[i]+"' >"+dv[i]+"</option>");
                        form.render('select')
                    }

                }

            })

        })

        form.on('select(test)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象

            var name=data.value
            $.ajax({
                url:"/user/selectname",
                type:"post",
                data:{"name":name},
                success:function (data){
                    var vip_user='';
                    var email='';
                    var u_phone='';
                    var sex='';
                    var age='';
                    var integral='';
                    $.each(JSON.parse(data),function (i,n){
                        email=n.email;
                        u_phone=n.u_phone;
                        sex=n.sex;
                        age=n.age;
                        integral=n.integral;
                    })

                    form.val('dataFrm', {
                         "name": name // "name": "value"
                        ,"email": email
                        ,"u_phone": u_phone
                        ,"sex": sex //复选框选中状态
                        ,"age": age //开关状态
                        ,"integral": integral
                    });

                }


            })
        });



        //提交表单
        form.on('submit(sub)', function (obj) {
            //序列化数据
            var params=$("#dataFrm").serialize();
            //解决序列化后乱码
            params = decodeURIComponent(params,true);
            $.ajax({
                type:"post",
            url:"/vip/addvip",
            data: params,
                success:function (data) {
                    if (data.trim() === "1") {
                        setTimeout('window.location.reload()',500);
                        layer.msg("添加成功")
                    } else {
                        layer.msg("失败")
                    }
                }
            })
        })
    });



</script>
<script src="static/js/config.js"></script>
<script src="static/js/script.js"></script>
</body>
</html>
